import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:ducafe_ui_core/ducafe_ui_core.dart';
import 'package:hive_flutter/hive_flutter.dart';

import '../../lib/view/home/widgets/publish_bottom_sheet.dart';
import '../../lib/common/index.dart';

void main() {
  group('PublishBottomSheet Tests', () {
    testWidgets('should display emotion selection page initially', (
      WidgetTester tester,
    ) async {
      await tester.pumpWidget(
        MaterialApp(home: Scaffold(body: PublishBottomSheet())),
      );

      // 验证第一页的标题存在
      expect(find.text('How are you feeling?'), findsOneWidget);
      expect(find.text('Choose your current emotion'), findsOneWidget);

      // 验证页面指示器显示1/2
      expect(find.text('1/2'), findsOneWidget);

      // 验证Next Step按钮存在
      expect(find.text('Next Step'), findsOneWidget);
    });

    testWidgets(
      'should navigate to content creation page when Next Step is tapped',
      (WidgetTester tester) async {
        await tester.pumpWidget(
          MaterialApp(home: Scaffold(body: PublishBottomSheet())),
        );

        // 选择一个情绪
        await tester.tap(find.text('😊').first);
        await tester.pumpAndSettle();

        // 点击Next Step按钮
        await tester.tap(find.text('Next Step'));
        await tester.pumpAndSettle();

        // 验证第二页的内容
        expect(find.text('Share your moment'), findsOneWidget);
        expect(find.text('Tell us what\'s on your mind'), findsOneWidget);

        // 验证页面指示器显示2/2
        expect(find.text('2/2'), findsOneWidget);

        // 验证Create Event按钮存在
        expect(find.text('Create Event'), findsOneWidget);
      },
    );

    testWidgets('should display emotion selection grid', (
      WidgetTester tester,
    ) async {
      await tester.pumpWidget(
        MaterialApp(home: Scaffold(body: PublishBottomSheet())),
      );

      // 验证情绪选项存在
      expect(find.text('😊'), findsOneWidget);
      expect(find.text('😢'), findsOneWidget);
      expect(find.text('😡'), findsOneWidget);
      expect(find.text('Happy'), findsOneWidget);
      expect(find.text('Sad'), findsOneWidget);
      expect(find.text('Angry'), findsOneWidget);
    });

    testWidgets('should display content creation elements on second page', (
      WidgetTester tester,
    ) async {
      await tester.pumpWidget(
        MaterialApp(home: Scaffold(body: PublishBottomSheet())),
      );

      // 导航到第二页
      await tester.tap(find.text('😊').first);
      await tester.pumpAndSettle();
      await tester.tap(find.text('Next Step'));
      await tester.pumpAndSettle();

      // 验证文本输入框
      expect(find.byType(TextField), findsOneWidget);
      expect(find.text('What\'s happening?'), findsOneWidget);

      // 验证媒体按钮
      expect(find.text('Photo'), findsOneWidget);
      expect(find.text('Video'), findsOneWidget);
      expect(find.text('Location'), findsOneWidget);
    });
  });
}
